Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/strings

Package Overview
Dependencies
Maintainers
1
Versions
196
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/strings

Various string formatting & utility functions

  • 1.15.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.8K
decreased by-32.42%
Maintainers
1
Weekly downloads
 
Created
Source

strings

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Various higher-order, configurable string formatting & utility functions, some memoized. Please sources / docstrings for now.

Partially based on Clojure version of thi.ng/strf.

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/strings
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/strings?module" crossorigin></script>

// UMD
<script src="https://unpkg.com/@thi.ng/strings/lib/index.umd.js" crossorigin></script>

Package sizes (gzipped, pre-treeshake): ESM: 3.65 KB / CJS: 3.94 KB / UMD: 3.74 KB

Dependencies

Usage examples

Several demos in this repo's /examples directory are using this package.

A selection:

ScreenshotDescriptionLive demoSource
Basic crypto-currency candle chart with multiple moving averages plotsDemoSource
Basic SPA example with atom-based UI routerDemoSource
rstream based spreadsheet w/ S-expression formula DSLDemoSource
XML/HTML/SVG to hiccup/JS conversionDemoSource

API

Generated API docs

Basic usage examples

// create a custom string formatter
const fmt = defFormat([
    "Price: ",
    { usd: "$", gbp: "£", eur: "€" },
    float(2),
    " (",
    percent(2),
    " off)"
]);

// use format
fmt("usd", 1.2345, 0.5);
// Price: $1.23 (50.00% off)

fmt("eur", 1.2345, 0.25)
// Price: €1.23 (25.00% off)

General

  • defFormat
  • format
  • hstr
  • ignore
  • interpolate
  • str

Case

  • camel
  • capitalize
  • kebab
  • lower
  • snake
  • slugify
  • upper

Numeric & radix-based

  • float
  • floatFixedWidth
  • maybeParseFloat
  • maybeParseInt
  • percent
  • radix
  • uuid
  • B8 / B16 / B32 - binary / bitstring presets
  • U8 / U16 / U24 / U32 / U64 - hex format presets (unsigned values)

Padding / truncation

  • center
  • padLeft
  • padRight
  • truncate
  • truncateLeft
  • wrap
  • Z2 / Z3 / Z4 - zero-pad presets

Units

  • units - define new unit w/ magnitudes & suffixes
  • bits
  • bytes
  • grams
  • meters
  • seconds

String creation & editing

  • charRange
  • repeat
  • splice

Authors

Karsten Schmidt

If this project contributes to an academic publication, please cite it as:

@misc{thing-strings,
  title = "@thi.ng/strings",
  author = "Karsten Schmidt",
  note = "https://thi.ng/strings",
  year = 2015
}

License

© 2015 - 2021 Karsten Schmidt // Apache Software License 2.0

Keywords

FAQs

Package last updated on 17 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc